<?php
include('generic_controller.php');
/* SVN FILE: $Id: pagination_app_controller.php 107 2007-04-14 17:07:09Z Andy $ */

/**
 * Short description for file.php.
 *
 * Long description for file
 *
 * PHP versions 4 and 5
 *
 * Copyright (c), Andy Dawson
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright    Copyright (c) 2007, Andy Dawson
 * @package      noswad
 * @subpackage   noswad.app.plugins.pagination
 * @since        Noswad site version 3
 * @todo         TODO Edit this block
 * @version      $Revision: 107 $
 * @created      26/01/2007
 * @modifiedby   $LastChangedBy$
 * @lastmodified $Date: 2007-04-14 19:07:09 +0200 (sáb, 14 abr 2007) $
 * @license      http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * Short description for Class
 *
 * Long descrption of Class
 */

/**
 * Description for var
 *
 * @var type
 * @access public/private/protected
 */

/**
 * Description for method
 *
 * @param type $name description
 * @return type description
 */
 class PaginationAppController extends GenericController {
	var $namedArgs = false;
	var $uses = array('Title');
	var $components = array ('Pagination','RequestHandler');
	var $helpers = array('Pagination','Ajax','Form');

	function beforeFilter () {
		$this->Menu->excludedActions[] = 'old_style_index';
		$this->modelClass = 'Title'; // Not necessary if conventions are followed
		parent::beforeFilter();
	}

	function beforeRender() {
		parent::beforeRender();
	}

	function admin_index() {
		$this->index();
	}

	function index() {
		list($order,$limit,$page) = $this->Pagination->init($criteria=null);
		$this->data = $this->{$this->modelClass}->findAll($criteria=null, null, $order, $limit, $page);
		$this->viewPath = 'normal';
		$this->render('index');
	}

	function old_style_index() {
		$criteria = null;
		$this->Pagination->init($criteria);
		$this->data = $this->{$this->modelClass}->findAll($criteria, null, $this->Pagination->order, $this->Pagination->limit, $this->Pagination->page);
		$this->viewPath = 'normal';
		$this->render('index');
	}

	function custom_index() {
		$options = array (
						"total"=>200, // overriding the number of results
						"sortByClass"=>"Category", // Different default sort class
						"sortBy"=>"name", // Different default sort field
						"showLimits"=>false // override the default to not show limits
						);
		list($order,$limit,$page) = $this->Pagination->init($criteria=null,null,$options);
		$this->data = $this->{$this->modelClass}->findAll($criteria=null, null, $order, $limit, $page);
		$this->viewPath = 'normal';
		$this->render('custom_index');
	}

	function extra_get_params() {
		if (count($_GET)<3) {
			return $this->redirect(array('?' => 'this=has&nothing=todo&with=pagination'));
		}
		$criteria = null;
		list($order,$limit,$page) = $this->Pagination->init($criteria);
		$this->data = $this->{$this->modelClass}->findAll($criteria, null, $order, $limit, $page);
		$this->viewPath = 'normal';
		$this->render('index');
	}

	function extra_params() {
		if (!$this->params['pass']) {
			return $this->redirect(array('this','has','nothing','todo','with','pagination'));
		}
		$criteria = null;
		list($order,$limit,$page) = $this->Pagination->init($criteria);
		$this->data = $this->{$this->modelClass}->findAll($criteria, null, $order, $limit, $page);
		$this->viewPath = 'normal';
		$this->render('index');
	}

	function no_limits() {
		$criteria = null;
		$options = array (
						"showLimits"=>false // override the default to not show limits
						);
		list($order,$limit,$page) = $this->Pagination->init($criteria,null,$options);
		$this->data = $this->{$this->modelClass}->findAll($criteria, null, $order, $limit, $page);
		$this->viewPath = 'normal';
		$this->render('index');
	}
}
?>